package org.teamh.gui.ingame.effects;

import java.nio.FloatBuffer;

public class ShotEffect extends Effect{
	
	private float startX;
	private float startY;
	private float startZ;
	
	
	private float endX;
	private float endY;
	private float endZ;
	
	private float duration;
	private float timeLasted;
	
	private Effect next;
	
	private float vecX;
	private float vecY;
	private float vecZ;
	
	private FloatBuffer modelviewMatrix;
	
	public ShotEffect(float startX, float startY, float startZ, float endX, float endY, float endZ) {
		this.startX = startX;
		this.startY = startY;
		this.startZ = startZ;
		
		this.endX = endX;
		this.endY = endY;
		this.endZ = endZ;
		
		vecX = (endX - startX);
		vecY = (endY - startY);
		vecZ = (endZ - startZ);
		
		modelviewMatrix = getEffectManager().getIngameFunctions().getModelviewMatrix();
	}
	
	@Override
	public void render(float timeElapsed) {
		timeLasted += timeElapsed;
		
		if(timeLasted >= duration) {
			getEffectManager().removeEffect(this);
			if(next != null) {
				getEffectManager().addEffect(next);
			}
		}
	}
	
	public void setDuration(float duration) {
		this.duration = duration;
		this.timeLasted = 0;
	}
	
	public float getDuration() {
		return duration;
	}
	
	public void setNext(Effect next) {
		this.next = next;
	}
	
	public float getStartX() {
		return startX;
	}
	
	public float getCurX() {
		return startX + vecX * timeLasted / duration;
	}
	
	public float getStartY() {
		return startY;
	}
	
	public float getCurY() {
		return startY + vecY * timeLasted / duration;
	}
	
	public float getStartZ() {
		return startZ;
	}
	
	public float getCurZ() {
		return startZ + vecZ * timeLasted / duration;
	}
	
	public float getVecX() {
		return vecX;
	}
	
	public float getVecY() {
		return vecY;
	}
	
	public float getVecZ() {
		return vecZ;
	}
	
	public void setVecX(float vecX) {
		this.vecX = vecX;
	}
	
	public void setVecY(float vecY) {
		this.vecY = vecY;
	}
	
	public void setVecZ(float vecZ) {
		this.vecZ = vecZ;
	}
	
	public void setEndX(float endX) {
		this.endX = endX;
	}
	
	public void setEndY(float endY) {
		this.endY = endY;
	}
	
	public void setEndZ(float endZ) {
		this.endZ = endZ;
	}
	
	public float getEndX() {
		return endX;
	}
	
	public float getEndY() {
		return endY;
	}
	
	public float getEndZ() {
		return endZ;
	}
	
	public float getDistance() {
		return (float)Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2) + Math.pow(endZ - startZ, 2));
	}
	
	@Override
	public EffectManager getEffectManager() {
		return super.getEffectManager();
	}
	
	public FloatBuffer getModelviewMatrix() {
		return modelviewMatrix;
	}
}
